<?php

namespace app\admin\controller;

use app\admin\model\Login as LoginModel;
use think\Controller;

class Login extends Controller
{

    private $login;

    protected function initialize()
    {
        parent::initialize();
        $this->login = new LoginModel();
    }

    /**
     * 展示登录首页
     * @return \think\response\View
     */
    function index()
    {
        return view();
    }

    /**
     * 登录操作
     */
    function login()
    {
        if (request()->isPost()) {

            $param = input('post.');

            $result = $this->login->login($param);

            if ($result == 1) {
                $this->success('登录成功!', url('/index'));
            } elseif ($result == 2) {
                $this->error('账号或者密码错误!');
            } elseif ($result == 3) {
                $this->error('您的账号已被禁用!');
            }
            $this->error('您无法登录!');
        }
    }

    /**
     * ajax检验用户名
     */
    function getUidByUsername() {
        // 需要检测的用户名
        $username = input('post.username');
        $id = $this->login->getUidByUsername($username);
        echo $id;
    }

}
